/**
@author		Jong Min, Lee
@date		  02/12/2014
@breif		study tab property

copyright(c) Tae Young Soft. All right reserved. 2014
*/
#include "stdafx.h"
#include "Taurus_Viewer/StudyTabProperty.h"
#include "Taurus_Util/Macros.h"
#include "Taurus_Common/IAppGlobalInstanceSet.h"
#include "Taurus_Common/MonitorAdmin.h"
#include "Taurus_Viewer/VGlobalInstanceSet.h"

#define STUDY_TAB_HEIGHT 40

CStudyTabProperty* CStudyTabProperty::m_theInstance = NULL;

CStudyTabProperty::CStudyTabProperty()
{
  init();
}

CStudyTabProperty::~CStudyTabProperty()
{
  destroy();
}

CStudyTabProperty* CStudyTabProperty::getInstance()
{
  if(m_theInstance == NULL)
    _TRY_ALLOC(m_theInstance, CStudyTabProperty)

  return m_theInstance;
}

DWORD CStudyTabProperty::importProperty()
{
  init();

  // TODO(Jong Min, Lee): import properties from viewer property
  m_theMaxNumTabs = 5;

  IAppGlobalInstanceSet* theAGSet = CVGlobalInstanceSet::getInstance()->getAppGlobalInstanceSet();
  CMonitorAdmin* theMAdmin = theAGSet->getMonitorAdmin();
  const unsigned int numMonitors = theMAdmin->getNumVisibleMonitors();
  try
  {
    m_theVisibilities.reserve(numMonitors);
  }
  catch(...)
  {
    init();
    return ERROR_NOT_ENOUGH_MEMORY;
  }

  for(unsigned int i = 0; i < numMonitors; ++i)
    m_theVisibilities.push_back(TRUE);

  return ERROR_SUCCESS;
}

DWORD CStudyTabProperty::exportProperty()
{
  // TODO(Jong Min, Lee): export current property to viewer property
  return ERROR_SUCCESS;
}

DWORD CStudyTabProperty::getVisibility(const unsigned int index, BOOL& visible) const
{
  if(index >= m_theVisibilities.size()) return ERROR_INVALID_PARAMETER;

  visible = m_theVisibilities[index];
  return ERROR_SUCCESS;
}

DWORD CStudyTabProperty::setVisibility(const unsigned int index, BOOL visible)
{
  if(index >= m_theVisibilities.size()) return ERROR_INVALID_PARAMETER;

  m_theVisibilities[index] = visible;
  return ERROR_SUCCESS;
}

int CStudyTabProperty::getTabHeight(MonitorResolutionType resType) const
{
  double resRatio = resType / static_cast<double>(100);

  return static_cast<int>(STUDY_TAB_HEIGHT * resRatio);
}

CStudyTabProperty::CFontProperty CStudyTabProperty::getFontProperty(MonitorResolutionType resType) const
{
  CFontProperty font;
  font.thePointSize = 14;
  font.theFaceName = _T("Tahoma");

  double resRatio = resType / static_cast<double>(100);

  font.thePointSize = static_cast<int>(font.thePointSize * resRatio);
  return font;
}

void CStudyTabProperty::init()
{
  m_theMaxNumTabs = 0;
  m_theVisibilities.clear();
}

void CStudyTabProperty::destroy()
{
}




